//
//  TableFormStackCell.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/6/3.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import CooperSwift

class TableFormStackCell: UITableViewCell {

    var bgView: UIStackView!
    
    var leftStackView: UIStackView!
    var leftLBs = Array<UILabel>()
    var leftImgs = Array<UIImageView>()
    var leftViews = Array<UIView>()
    
    var rightStackView: UIStackView!
    var rightLBs = Array<UILabel>()
    var rightImgs = Array<UIImageView>()
    var rightViews = Array<UIView>()
    
    var centerStackView: UIStackView!
    var centerLeftViews = Array<UIView>()
    var centerLeftLBs = Array<UILabel>()
    var centerLeftImgs = Array<UIImageView>()
    
    
    var centerViews = Array<UIView>()
    
    var centerRightViews = Array<UIView>()
    var centerRightLBs = Array<UILabel>()
    var centerRightImgs = Array<UIImageView>()
    
    var bottonLineView: UIView!
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        layoutViews()
    }
    
    override func bindTo(_ info: Any?) {
        
        if self.info == nil {
            
            guard let config = info as? FormStackCellModelProtocol else {
                return
            }
            
            config.configOnceCenterContentTF(centerViews[0] as! UITextField)
            config.configOnceCenterContentLB(centerViews[1] as! UILabel)
            config.configOnceCenterContentTV(centerViews[2] as! UITextView)
            config.configOnceCenterContentBT(centerViews[3] as! UIButton)
            
            // MARK: - base
            config.configBgView(bgView, cell: self)
            config.configLeftStackView(leftStackView, bgView: bgView)
            config.configCenterStackView(centerStackView, bgView: bgView)
            config.configRightStackView(rightStackView, bgView: bgView)
            
        }
        
        self.info = info
        
        guard let config = info as? FormStackCellModelProtocol else {
            return
        }
        
        // MARK: - left
        
        config.configLeftViews(leftViews)
        config.configLeftImgs(leftImgs)
        config.configLeftLBs(leftLBs)
        
        config.configLeftView0(leftViews[0])
        
        config.configLeftLB1(leftLBs[0])
        config.configLeftLB2(leftLBs[1])
        config.configLeftLB3(leftLBs[2])
        config.configLeftLB4(leftLBs[3])
        
        config.configLeftImgV1(leftImgs[0])
        config.configLeftImgV2(leftImgs[1])
        config.configLeftImgV3(leftImgs[2])
        config.configLeftImgV4(leftImgs[3])
        
        // MARK: - right
        config.configRightViews(rightViews)
        config.configRightImgs(rightImgs)
        config.configRightLBs(rightLBs)
        
        config.configRightView0(rightViews.last!)
        
        let rightLabels = rightLBs.reversed().map { $0 }
        config.configRightLB1(rightLabels[0])
        config.configRightLB2(rightLabels[1])
        config.configRightLB3(rightLabels[2])
        config.configRightLB4(rightLabels[3])
        
        let rightImages = rightImgs.reversed().map { $0 }
        config.configRightImgV1(rightImages[0])
        config.configRightImgV2(rightImages[1])
        config.configRightImgV3(rightImages[2])
        config.configRightImgV4(rightImages[3])
        
        // MARK: - center stack
        // center left
        config.configCenterLeftViews(centerLeftViews)
        config.configCenterLeftImgs(centerLeftImgs)
        config.configCenterLeftLBs(centerLeftLBs)
        
        config.configCenterLeftLB1(centerLeftLBs[0])
        config.configCenterLeftLB2(centerLeftLBs[1])
        config.configCenterLeftImgV1(centerLeftImgs[0])
        config.configCenterLeftImgV2(centerLeftImgs[1])
        
        // center center
        config.configCenterContentTF(centerViews[0] as! UITextField)
        config.configCenterContentLB(centerViews[1] as! UILabel)
        config.configCenterContentTV(centerViews[2] as! UITextView)
        config.configCenterContentBT(centerViews[3] as! UIButton)
        
        // center right
        config.configCenterRightViews(centerRightViews)
        config.configCenterRightImgs(centerRightImgs)
        config.configCenterRightLBs(centerRightLBs)
        
        let centerRightLabels = centerRightLBs.reversed().map { $0 }
        config.configCenterRightLB1(centerRightLabels[0])
        config.configCenterRightLB2(centerRightLabels[1])
        let centerRightImages = centerRightImgs.reversed().map { $0 }
        config.configCenterRightImgV1(centerRightImages[0])
        config.configCenterRightImgV2(centerRightImages[1])
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
